/* 系统公用方法 */
(function (win, doc) {
    var admin = {
        basePath: function () {
            var curWwwPath = window.document.location.href;
            var pathName = window.document.location.pathname;
            var pos = curWwwPath.indexOf(pathName);
            var localhostPath = curWwwPath.substring(0, pos);
            var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
            var path = localhostPath + projectName + "/";
            return path;
        },
        //只能输入数字
        nuberInteger:function(obj){
            var inpVal = obj.val();
            obj.val(inpVal.replace(/\D|^0/g,''));
        },
        myTofixed : function(num,n){
            var n=n||2;//默认保留两位小数
            var number=num;
            var multipe=Math.pow(10,n); //把一个数放大10的次方倍
            if(!isNaN(number)){
                number=Math.round(number*multipe);//四舍五入
                //处理小数点
                number=number.toString().split("");
                if(number.length<n+1){//当数值小于1的时候的处理方法
                    for(var i=0;i<=n+1-number.length;i++){
                        number.splice(0, 0,"0");
                    }
                }
                number.splice(number.length-n, 0,".");  //给一个放大后的数的字符串插入小数点
                number=number.join("");
                return number
            }else{
                return 0;
            }
        },
        //金钱格式
        fmoney: function(s, n){
            /*
             * 参数说明：
             * s：要格式化的数字
             * n：保留几位小数
             * */
            n = n > 0 && n <= 20 ? n : 2;
            //s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
            var  s1 = parseFloat((s + "").replace(/[^\d\.-]/g, ""));
            var  s2 = admin.myTofixed(s1,n);

            if(s2 == 0){
                return "0.00";
            }
            s = s2 + "";
            var l = s.split(".")[0].split("").reverse(),r = s.split(".")[1];
            t = "";
            for (var i = 0; i < l.length; i++) {//遍历值
                if(s<0){
                    t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length-1 ? "," : "");
                }else{
                    t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
                }
            }

            var q  = t.split("").reverse().join("") + "." + r;
            if(s<0){ //判断值小于0
                var ma = q.substr(0,1);
                if(ma == ","){
                    var sd = q.replace(ma,'');
                    return sd;
                }

            }else{

                return t.split("").reverse().join("") + "." + r;
            }
            return t.split("").reverse().join("") + "." + r;

        },
        //去掉金钱格式
        rmoney: function(s){
            return parseFloat(s.replace(/[^\d\.-]/g, ""));
        },
        // 只能输入数字和小数点且保留两位小数
        changeFee:function ($this) {
            var tmptxt = $this.val();
            $this.val(tmptxt.replace(/[^\d.]/g, '').replace(/^\./g, "").replace(
                /\.{2,}/g, ".").replace(".", "$#$").replace(/\./g, "").replace(
                "$#$", ".").replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'));
        },
        screen: function () {
            var w = $(window).width();
            return w >= 1200 ? 3 : w >= 992 ? 2 : w >= 768 ? 1 : 0;
        },
        //获取公司年月日（2014-xxxx）
        copyrightYear: function (id) {
            var copyrightYear = new Date().getFullYear();
            if (copyrightYear < 2022) { $(id).html(copyrightYear + "-2022"); }
            else if (copyrightYear == 2022) { $(id).html(copyrightYear); }
            else { $(id).html("2022-" + copyrightYear); }
        },
        //删除/停用/启用/上线/下线操作
//        handle: function (o, fn) {
//            var type = $(o).attr("data-type");
//            var title = $(o).attr("data-title");
//            var name = $(o).attr("data-name");
//            if (typeof name === "undefined") {
//                name == "";
//            } else {
//                name = $(o).attr("data-name")
//            }
//            if (type == "batch") {
//                layer.confirm(
//                    "确认要<strong class='pad-hor text-danger'>" + title + "</strong>选中的记录吗？", {
//                    closeBtn: 0,
//                    title: "系统提示",
//                    shade: [0.1, "#000"]
//                }, function (index) {
//                    layer.close(index);
//                    if (fn != "" && $.isFunction(fn)) fn();
//                }
//                );
//            } else {
//                layer.confirm(
//                    "确认要<strong class='pad-hor text-danger'>" + title + " " + name + " </strong>此条记录吗？", {
//                    closeBtn: 0,
//                    title: "系统提示",
//                    shade: [0.1, "#000"]
//                }, function (index) {
//                    layer.close(index);
//                    if (fn != "" && $.isFunction(fn)) fn();
//                }
//                );
//            }
//        },
        closePage: function () {
            layer.closeAll('page');
        },
        closeIframePage: function () {
            parent.layer.closeAll('page');
        },
        //打开外链
        iframeLink: function (o) {
            var index = layer.getFrameIndex(window.name);
            var w = $(o).attr("data-width") ? $(o).attr("data-width") : $(window.parent.window).width() * 0.9,
                h = $(o).attr("data-height") ? $(o).attr("data-height") : $(window.parent.window).height() * 0.9;
            var title = $(o).attr("data-title"),
                url = $(o).attr("data-href");
            var closeBtn = $(o).attr("data-closebtn");
            if (closeBtn == undefined || closeBtn == true) {
                closeBtn = 1
            } else {
                closeBtn = 0
            }
            var maxmin = $(o).attr("data-maxmin");
            if (maxmin == undefined || maxmin == true) {
                maxmin = true
            } else {
                maxmin = false
            }
            layer.open({
                type: 2,
                title: title,
                closeBtn: closeBtn,
                maxmin: maxmin,
                area: admin.screen() < 2 ? ['94%', '94%'] : [w + "px", h + "px"],
                content: [url, "yes"]
            });
        },
        //系统内部
        iframe: function (o) {
            var layer = window.layer;
            //var index = layer.getFrameIndex(window.parent.window.name);
            var index = layer.getFrameIndex();
            var w = $(o).attr("data-width") ? $(o).attr("data-width") : document.documentElement.clientWidth * 0.9,
                h = $(o).attr("data-height") ? $(o).attr("data-height") : document.documentElement.clientHeight * 0.9;
            var title = $(o).attr("data-title"),
                url = $(o).attr("data-href") ? $(o).attr("data-href") : $(o).attr("data-url"),
                t = (new Date()).valueOf();
            if ((url.indexOf("?") >= 0)) {
                url = url + "&t=" + t;
            } else {
                url = url + "?t=" + t;
            }
            var closeBtn = $(o).attr("data-closebtn");
            if (closeBtn == undefined || closeBtn == true) {
                closeBtn = 1
            } else {
                closeBtn = 0
            }
            var maxmin = $(o).attr("data-maxmin");
            if (maxmin == undefined || maxmin == true) {
                maxmin = true
            } else {
                maxmin = false
            }
            var endFn = $(o).attr("data-end-fn");
            layer.open({
                type: 2,
                title: title,
                closeBtn: closeBtn,
                maxmin: maxmin,
                area: admin.screen() < 2 ? ['94%', '94%'] : [w + "px", h + "px"],
                content: [url, "yes"],
                success: function (layero, index) {
//                    layer.full(index);
//                    layer.iframeAuto(index);
                }, 
                end: function (){
                	if (typeof endFn != "undefined") {
						eval(endFn);
					}
                }

            });
        },
        //系统内部
        dialog: function (o, fn) {
            var layer = window.layer;
            var index = layer.getFrameIndex();
            var w = $(o).attr("data-width") ? $(o).attr("data-width") : $(window).width() * 0.9,
                h = $(o).attr("data-height") ? $(o).attr("data-height") : $(window).height() * 0.9;
            var auto = $(o).attr("data-auto");
            var title = $(o).attr("data-title"),
                url = $(o).attr("data-href") ? $(o).attr("data-href") : $(o).attr("data-url"),
                t = (new Date()).valueOf();
            if ((url.indexOf("?") >= 0)) {
                url = url + "&t=" + t;
            } else {
                url = url + "?t=" + t;
            }
            var closeBtn = $(o).attr("data-closebtn");
            if (closeBtn == undefined || closeBtn == true) {
                closeBtn = 1
            } else {
                closeBtn = 0
            }
            var maxmin = $(o).attr("data-maxmin");
            if (maxmin == undefined || maxmin == true) {
                maxmin = true
            } else {
                maxmin = false
            }
            $.get(url, function (res) {
                layer.open({
                    shade: $(o).attr("data-shade") == 0 ? 0 : 0.3,
                    id: $(o).attr("data-id"),
                    type: 1,
                    title: title,
                    closeBtn: closeBtn,
                    maxmin: maxmin,
                    area: admin.screen() < 2 ? ['94%', '94%'] : auto ? ["auto", "auto"] : [w + "px", h + "px"],
                    content: res,
                    success: (fn != "" && $.isFunction(fn)) ? fn : null
                });
            });

        },
        //表单提交
//        ajaxForm: function (formId, url, o, fn) {
//            if ($(formId).valid()) {
//                var datas = JSON.stringify($(formId).serializeJSON());
//                $.ajax({
//                    type: 'POST',
//                    xhrFields: {
//                        withCredentials: true
//                    },
//                    crossDomain: true,
//                    async: true,
//                    url: portalUrl,
//                    dataType: 'json',
//                    data: datas,
//                    contentType: "application/json",
//                    timeout: 30000,
//                    success: function (data) {
//                        var code = data.code,
//                            msg = data.msg;
//                        if (data.code === 0) {
//                            if (fn != "" && $.isFunction(fn)) fn(data);
//                        } else {
//                            $(o).removeAttr("disabled").html("保存");
//                        }
//                    }
//                });
//            }
//        },
        //日期控件处理  // obj obj 日期输入框 dobubble  是否为双日期（true） second 有无时分（有则true）
        calenders: function (obj, dobubble, second) {
            var singleNot, formatDate, calendersRanges;
            if (dobubble == true) {
                singleNot = false;
                calendersRanges = {
                    '昨日': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')],
                    '今日': [moment().startOf('day'), moment()],
                    '最近7日': [moment().subtract(6, 'days'), moment()],
                    '本月': [moment().startOf("month"), moment().endOf("month")],
                    '最近30日': [moment().subtract(29, 'days'), moment()],
                    '上个月': [moment().subtract(1, "month").startOf("month"), moment().subtract(1, "month").endOf("month")],
                    '最近三个月': [moment().subtract(3, "month").startOf("month"), moment().endOf("month")]
                }
            } else {
                singleNot = true;
                calendersRanges = {
                    '昨日': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')],
                    '今日': [moment().startOf('day'), moment()]
                }
            }
            if (second == true) {
                formatDate = "YYYY-MM-DD HH:mm";
            } else {
                formatDate = "YYYY-MM-DD";
            }
            var calendersLocale = {
                format: formatDate,
                applyLabel: "确定",
                cancelLabel: "取消",
                fromLabel: "起始时间",
                toLabel: "结束时间",
                customRangeLabel: "自定义",
                daysOfWeek: ["日", "一", "二", "三", "四", "五", "六"],
                monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                firstDay: 1
            }
            $(obj).daterangepicker({
                "ranges": calendersRanges,
                "singleDatePicker": singleNot,
                "timePicker": second,
                "timePicker24Hour": second,
                "timePickerSeconds": false,
                "showDropdowns": true,
                "timePickerIncrement": 1,
                "linkedCalendars": false,
                "autoApply": true,
                "autoUpdateInput": false,
                "alwaysShowCalendars": true,
                "opens": "right",
                "buttonClasses": ['btn btn-default'],
                "applyClass": 'btn-small btn-primary blue',
                "cancelClass": 'btn-small',
                "locale": calendersLocale
            }, function (start, end) {
                if (second == true && dobubble == true) {
                    //双日历 日期 + 时分
                    $(obj).val($.trim(start.format('YYYY-MM-DD HH:mm') + ' - ' + end.format('YYYY-MM-DD HH:mm')));
                    $(obj).next().val(start.format('YYYY-MM-DD HH:mm')).next().val(end.format('YYYY-MM-DD HH:mm'));
                } else if (second == false && dobubble == true) {
                    //双日历 日期
                    $(obj).val($.trim(start.format('YYYY-MM-DD') + ' - ' + end.format('YYYY-MM-DD')));
                    $(obj).next().val(start.format('YYYY-MM-DD')).next().val(end.format('YYYY-MM-DD'));
                } else if (second == false && dobubble == false) {
                    //单日历 日期
                    $(obj).val(start.format('YYYY-MM-DD'));
                } else if (second == true && dobubble == false) {
                    //单日历 日期 + 时分
                    $(obj).val(start.format('YYYY-MM-DD HH:mm'));
                }
            });
            //清空
            $(obj).on('cancel.daterangepicker', function (ev, picker) {
                $(this).val('').next().val("").next().val("");
            });
        },
        //数字转换为大写
        digitUppercase: function (n) {
            var fraction = ['角', '分'];
            var digit = [
                '零', '壹', '贰', '叁', '肆',
                '伍', '陆', '柒', '捌', '玖'
            ];
            var unit = [
                ['元', '万', '亿'],
                ['', '拾', '佰', '仟']
            ];
            var head = n < 0 ? '欠' : '';
            n = Math.abs(n);
            var s = '';
            for (var i = 0; i < fraction.length; i++) {
                s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
            }
            s = s || '整';
            n = Math.floor(n);
            for (var i = 0; i < unit[0].length && n > 0; i++) {
                var p = '';
                for (var j = 0; j < unit[1].length && n > 0; j++) {
                    p = digit[n % 10] + unit[1][j] + p;
                    n = Math.floor(n / 10);
                }
                s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
            }
            return head + s.replace(/(零.)*零元/, '元')
                .replace(/(零.)+/g, '零')
                .replace(/^整$/, '零元整');
        },
        //替换html
        htmlReplace: function (str) {
            str = str.replace(/&/g, '＆');
            str = str.replace(/</g, '＜');
            str = str.replace(/>/g, '＞');
            str = str.replace(/\!/g, '！');
            str = str.replace(/\|/g, '｜');
            str = str.replace(/\./g, '．');
            str = str.replace(/\^/g, '＾');
            str = str.replace(/\$/g, '＄');
            str = str.replace(/\&/g, '＆');
            str = str.replace(/\*/g, '＊');
            str = str.replace(/=/g, '＝');
            return str;
        },
        //截取长度
        cutstr: function (str, len) {
            var str_length = 0;
            var str_len = 0;
            var str_cut = new String();
            var str_len = str.length;
            for (var i = 0; i < str_len; i++) {
                var a = str.charAt(i);
                str_length++;
                if (escape(a).length > 4) {
                    str_length++;
                }
                str_cut = str_cut.concat(a);
                if (str_length >= len) {
                    str_cut = str_cut.concat("...");
                    return str_cut;
                }
            }
            if (str_length < len) {
                return str;
            }
        },
        strTobool: function (str) {
            return (str && typeof str == 'string') ? (str.toLowerCase() == 'true' || str == '1') : (str == true);
        },
        //获取URL参数 key 参数名称 url URL链接，默认为当前URL
        getUrlKey: function (key, url) {
            var url = url ? url : location.href;
            var v = '';
            var o = url.indexOf(key + "=");
            if (o != -1) {
                o += key.length + 1;
                e = url.indexOf("&", o);
                if (e == -1) {
                    e = url.length;
                }
                //v = decodeURIComponent(url.substring(o, e));
                v = url.substring(o, e);
            }
            return v;
        },
        //计时
        countTime: function (o, fn) {
            $(o).each(function () {
                var endtime = new Date($(this).attr("endtime")).getTime();
                var nowtime = new Date().getTime();
                var youtime = endtime - nowtime;
                var seconds = Math.floor(youtime / 1000);
                var minutes = Math.floor(seconds / 60);
                var hours = Math.floor(minutes / 60);
                var days = Math.floor(hours / 24);
                var CDay = days;
                var CHour = Math.floor(hours % 24);
                var CMinute = Math.floor(minutes % 60);
                var CSecond = Math.floor(seconds % 60);
                if (CDay < 10) { CDay = "0" + CDay; }
                if (CHour < 10) { CHour = "0" + CHour; }
                if (CMinute < 10) { CMinute = "0" + CMinute; }
                if (CSecond < 10) { CSecond = "0" + CSecond; }
                if (endtime <= nowtime) {
                    $(this).hide();
                    $(this).next().hide();
                    $(this).html("<span class='countTimeExp'>&nbsp;</span>");
                    console.log("倒计时完毕");
                    if (fn != "" && $.isFunction(fn)) fn();
                    return false;
                } else {
                    if ($(this).attr("showDate") == "yes") {
                        $(this).html("<span class='countTimeBox'><em>倒计时</em></span><span class='countDay'>" + days + "</span><em>天</em><span class='countHour'>" + CHour + "</span><em>:</em><span class='countMinu'>" + CMinute + "</span><em>:</em><span class='countSec'>" + CSecond + "</span>");
                    } else {
                        $(this).html("<span class='countTimeBox'><em>倒计时</em></span><span class='countHour'>" + CHour + "</span><em>:</em><span class='countMinu'>" + CMinute + "</span><em>:</em><span class='countSec'>" + CSecond + "</span>");
                    }
                }
            });
            setTimeout(function () {
                admin.countTime(o, fn)
            }, 1000);
        },
        //获取全部cookies
        getAllCookies: function () {
            if (document.cookie) {
                var aCookie = document.cookie.split(";");
                var re = "";
                for (var i = 0; i < aCookie.length; i++) {
                    var aCrumb = aCookie[i].split("=");
                    re += (aCrumb[0] + ":" + aCrumb[1] + '\n');
                }
                return re;
            } else {
                return "无cookie"
            }
        },
        //是否支持cookies
        isCookie: function () {
            if (window.navigator.cookieEnabled) {
                return true;
            } else {
                return false;
            }
        },
        //是否支付本地缓存
        isLocalStorage: function () {
            if (window.localStorage) {
                return true;
            } else {
                return false;
            }
        },
        error: function (info) {
            layer.msg(info)
        },
        /*
        *@param s 即将被转化的字符  String
        *@param num 字符的间隔    Number
        *@param type 字符的类型  String
        */
        getSpace: function (s, num, type) {
            //过滤了空格的存在、实际中根据需求是否必须去掉空格
            s = s.replace(/\s*/g, '');
            if (s.length === 0) {
                return '';
            }
            if (s.length < num && s.length !== 0) {
                return s;
            }
            var m, n, res = '';
            var reg = new RegExp('(\\w{' + num + '})', 'g');
            var reg2 = new RegExp('(?:\\w{' + num + '})+(\\w+)', 'g');
            var reg3 = new RegExp('' + type + '$');
            while (m = reg.exec(s)) {
                res += m[1] + type;
            }
            if (s.length % num == 0) {
                return res.replace(reg3, '');
            } else {
                var n = reg2.exec(s);
                return (res + n[1]);
            }
        },
    };
    win.admin = admin;
}(window, document));

$(function () {
    $.ajaxSetup({
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        timeout: 20000,
        error: function (xhr, textStatus) {
            layer.closeAll('loading');
            if (xhr.status == 2000) {//session超时
                alert("session超时");
                return;
            } else if (xhr.status == 404) {
                admin.error("您访问的页面已经删除或者不存在")
                return;
            } else if (xhr.status == 500) {
                alert("服务器内部错误");
                return;
            }
            if (textStatus == "error") {
                layer.msg("网络异常！")
            } else if (textStatus == 400) {
                alert("请求不存在。");
            }
        },
        complete: function (xhr, textStatus) {
            layer.closeAll('loading');
            $("#admin-loading").hide()
            if (xhr.status == 2000) {//session超时
                alert("session超时");
                return;
            } else if (xhr.status == 404) {
                admin.error("您访问的页面已经删除或者不存在")
                return;
            } else if (xhr.status == 500) {
                alert("服务器内部错误");
                return;
            }
            if (textStatus == "error") {
                layer.msg("网络异常！")
            } else if (textStatus == 400) {
                alert("请求不存在。");
            }
        }
    });
    admin.copyrightYear("#copyrightYear");
});

Array.prototype.contains = function(val) {
    for (var i = 0; i < this.length; i++) {
      if (this[i] == val) {
          return true;
      }
    }
    return false;
};

String.prototype.replaceAll = function(s1, s2){ 
	return this.replace(new RegExp(s1,"gm"),s2); 
};

var input = {
	amount : function(o) {
		$(o).keyup(function () {
			var reg = $(this).val().match(/\d+\.?\d{0,2}/);
			if ($(this).attr("data-scale") && $(this).attr("data-scale") == "4") {
				reg = $(this).val().match(/\d+\.?\d{0,4}/);
			}
			var txt = '';
			if (reg != null) {
				txt = reg[0];
			}
			$(this).val(txt);
		}).change(function () {
			$(this).keypress();
			var v = $(this).val();
			if (/\.$/.test(v)) {
				$(this).val(v.substr(0, v.length - 1));
			}
		});
	},
	int : function(o) {
		$(o).keyup(function () {
			this.value=this.value.replace(/[^\d]/g,'');
		});
	},
	month : function(o) {
		$(o).blur(function () {
			var reg=/^[0-9]{4}-(0[1-9]|1[0-2])$/;
			if (!reg.test(this.value)) {
				this.value = "";
			}
		});
	}
}

var math = {
	add : function(arg1, arg2, num) {
		arg1 = Number(arg1);
		arg2 = Number(arg2);
		var r1 = 0, r2 = 0, m
		try {
			r1 = arg1.toString().split('.')[1].length;
		} catch (e) {
		}
		try {
			r2 = arg2.toString().split(".")[1].length;
		} catch (e) {
		}
		m = Math.pow(10, Math.max(r1, r2));
		if (num || num === 0) {
			return ((arg1 * m + arg2 * m) / m).toFixed(num) // 注意：fixed四舍五入大于5会进1
															// 5并不会进1
		}
		return (arg1 * m + arg2 * m) / m;
	},
	sub : function(arg1, arg2, num) {
		arg1 = Number(arg1);
		arg2 = Number(arg2);
		var r1 = 0, r2 = 0, m
		try {
			r1 = arg1.toString().split('.')[1].length;
		} catch (e) {
		}
		try {
			r2 = arg2.toString().split(".")[1].length;
		} catch (e) {
		}
		m = Math.pow(10, Math.max(r1, r2));
		if (num || num === 0) {
			return ((arg1 * m - arg2 * m) / m).toFixed(num) // 注意：fixed四舍五入大于5会进1
															// 5并不会进1
		}
		return (arg1 * m - arg2 * m) / m
	},
	mul : function(arg1, arg2, num) {
		var m = 0, s1 = arg1.toString(), s2 = arg2.toString();// 获取两个相乘数据的小数点后面的数据的长度，即获取小数的位数，因为最终相乘计算的结果：结果小数的位数=第一个数的小数位数+第二个数的小数位数
		try {
			m += s1.split(".")[1].length;
		} catch (e) {
		}
		try {
			m += s2.split(".")[1].length;
		} catch (e) {
		}// 将两个小数去掉小数点，强制转换整个值（即进行数值放开小数点位数的倍数），然后进行相乘的操作，相乘的结果除去10的m次方
		if (num || num === 0) {
			return (Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math
					.pow(10, m)).toFixed(num) // 注意：fixed四舍五入大于5会进1 5并不会进1
		}
		return Number(s1.replace(".", "")) * Number(s2.replace(".", ""))
				/ Math.pow(10, m);
	},
	div : function(arg1, arg2, num) {
		var t1 = 0, t2 = 0, r1, r2;
		if (arg2 == 0) {
			return Number(arg2).toFixed(num);
		}
		try {
			t1 = arg1.toString().split(".")[1].length
		} catch (e) {
		}
		try {
			t2 = arg2.toString().split(".")[1].length
		} catch (e) {
		}
		r1 = Number(arg1.toString().replace(".", ""))
		r2 = Number(arg2.toString().replace(".", ""))
		if (num || num === 0) {
			return ((r1 / r2) * Math.pow(10, t2 - t1)).toFixed(num);
		}
		return (r1 / r2) * Math.pow(10, t2 - t1);
	},
	round : function(arg1, num) {
		return Number(arg1).toFixed(num);
	}
}

var cal = {
	currentDate : new Date(),
	millisecond : 1000 * 60 * 60 * 24,//一天的毫秒数
	formatterDate : function(date) {
		var datetime = date.getFullYear()
				+ "-"// "年"
				+ ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
						+ (date.getMonth() + 1)) + "-"// "月"
				+ (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());
		return datetime;
	},
	getToday : function() {
		return cal.formatterDate(cal.currentDate);
	},
	getYesterday : function() {
		var day = new Date(cal.currentDate.getTime() - cal.millisecond);
        return cal.formatterDate(day);
	},
	getThisWeek : function() {
		//起止日期数组
		var startStop = new Array();
		//返回date是一周中的某一天
		var week = cal.currentDate.getDay();
		//减去的天数
		var minusDay = week != 0 ? week - 1 : 6;
		//本周 周一
		var monday = new Date(cal.currentDate.getTime()
				- (minusDay * cal.millisecond));
		//本周 周日
		var sunday = new Date(monday.getTime() + (6 * cal.millisecond));
		//添加本周时间
		startStop.push(cal.formatterDate(monday)); //本周起始时间
		//添加本周最后一天时间
		startStop.push(cal.formatterDate(sunday)); //本周终止时间
		//返回
		return startStop;
	},
	getLastWeek : function() {
		//起止日期数组
		var startStop = new Array();
		//返回date是一周中的某一天
		var week = cal.currentDate.getDay();
		//减去的天数
		var minusDay = week != 0 ? week - 1 : 6;
		//获得当前周的第一天
		var currentWeekDayOne = new Date(cal.currentDate.getTime()
				- (cal.millisecond * minusDay));
		//上周最后一天即本周开始的前一天
		var priorWeekLastDay = new Date(currentWeekDayOne.getTime()
				- cal.millisecond);
		//上周的第一天
		var priorWeekFirstDay = new Date(priorWeekLastDay.getTime()
				- (cal.millisecond * 6));

		startStop.push(cal.formatterDate(priorWeekFirstDay));
		startStop.push(cal.formatterDate(priorWeekLastDay));
		//返回
		return startStop;
	},
	getThisMonth : function() {
		var startStop = new Array();
		//获得当前月份0-11
		var currentMonth = cal.currentDate.getMonth();
		//获得当前年份4位年
		var currentYear = cal.currentDate.getFullYear();
		//求出本月第一天
		var firstDay = new Date(currentYear, currentMonth, 1);
		//当为12月的时候年份需要加1
		//月份需要更新为0 也就是下一年的第一个月
		//否则只是月份增加,以便求的下一月的第一天
		if (currentMonth == 11) {
			currentYear++;
			currentMonth = 0;
		} else {
			currentMonth++;
		}
		//下月的第一天
		var nextMonthDayOne = new Date(currentYear, currentMonth, 1);
		//求出上月的最后一天
		var lastDay = new Date(nextMonthDayOne.getTime()
				- cal.millisecond);

		startStop.push(cal.formatterDate(firstDay));
		startStop.push(cal.formatterDate(lastDay));
		//返回
		return startStop;
	},
	getLastMonth : function() {
		var startStop = new Array();
		//获得当前月份0-11
		var currentMonth = cal.currentDate.getMonth();
		//获得当前年份4位年
		var currentYear = cal.currentDate.getFullYear();
		var currentDay = new Date(currentYear, currentMonth, 1);
		//上个月的第一天
		//年份为0代表,是本年的第一月,所以不能减
		if (currentMonth == 0) {
			currentMonth = 11; //月份为上年的最后月份
			currentYear--; //年份减1
		} else {
			currentMonth--;
		}
		var firstDay = new Date(currentYear, currentMonth, 1);
		//求出上月的最后一天
		var lastDay = new Date(currentDay.getTime() - cal.millisecond);

		startStop.push(cal.formatterDate(firstDay));
		startStop.push(cal.formatterDate(lastDay));
		//返回
		return startStop;
	},
	getQuarter1 : function() {
		var startStop = new Array();
		var currentYear = cal.currentDate.getFullYear();
		startStop.push(currentYear + "-01-01");
		startStop.push(currentYear + "-03-31");
		return startStop;
	},
	getQuarter2 : function() {
		var startStop = new Array();
		var currentYear = cal.currentDate.getFullYear();
		startStop.push(currentYear + "-04-01");
		startStop.push(currentYear + "-06-30");
		return startStop;
	},
	getQuarter3 : function() {
		var startStop = new Array();
		var currentYear = cal.currentDate.getFullYear();
		startStop.push(currentYear + "-07-01");
		startStop.push(currentYear + "-09-30");
		return startStop;
	},
	getQuarter4 : function() {
		var startStop = new Array();
		var currentYear = cal.currentDate.getFullYear();
		startStop.push(currentYear + "-10-01");
		startStop.push(currentYear + "-12-31");
		return startStop;
	},
	getThisYear : function() {
		var startStop = new Array();
		var currentYear = cal.currentDate.getFullYear();
		startStop.push(currentYear + "-01-01");
		startStop.push(currentYear + "-12-31");
		return startStop;
	},
	getLastYear : function() {
		var startStop = new Array();
		var currentYear = cal.currentDate.getFullYear() - 1;
		startStop.push(currentYear + "-01-01");
		startStop.push(currentYear + "-12-31");
		return startStop;
	}
}

//多选赋值，改成select上加  data-input=inputId
/*unction setSelectVal(obj,inputId) {
    $("#" + inputId).val($(obj).val());
}*/
